#测试帖子编辑页
import time

from selenium.webdriver.common.by import By
from Test.ForumLoginTest import Login


from commond.Utils import ForumDriver
class ForumEdit:
    driver=""
    url=""
    def __init__(self):
        self.driver=ForumDriver.driver
        self.url="http://127.0.0.1:9580/index.html"
        self.driver.get(self.url)

    def File_Edit(self):
        self.url="http://127.0.0.1:9580/index.html"
        self.driver.get(self.url)
        Login.Check_Ele_Login()

    def Check_Edit_Ele(self):
        # 页面元素检查
        time.sleep(2)
        # 板块
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div.card-body > div:nth-child(1) > label > strong")
        # 标题
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div.card-body > div:nth-child(2) > label > strong")
        # 内容
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-body > div > div > div.card-body > div:nth-child(3) > label > strong")

    #成功发布帖子，但是编辑区无法交互
    def Suc_Send(self):
        # 发布新帖，模板默认
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").send_keys("mxj测试编辑页10096")
        self.driver.find_element(By.CSS_SELECTOR,"#edit-article > div.CodeMirror.cm-s-default.CodeMirror-wrap.CodeMirror-empty > div.CodeMirror-scroll > div.CodeMirror-sizer > div").send_keys("测试")
        time.sleep(2)
        #将滑动条滑动到底部
        # self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
        # time.sleep(0.5)
        # self.driver.find_element(By.CSS_SELECTOR, "#article_post_submit").click()
        self.driver.find_element(By.ID, "article_post_submit")
        time.sleep(3)
        #点击发布后会回到论坛首页，通过截图判断是否发布成功
        #BUG:在论坛列表中看到，显示发布的时间与实际不一致
        ForumDriver.getScreenshot()

    def Fail_Send(self):

        #输入标题，不输入内容
        self.driver.find_element(By.CSS_SELECTOR,"#article_post_title").send_keys("mxj")
        time.sleep(5)
        #滑动到底部
        self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
        time.sleep(0.5)

        self.driver.find_element(By.CSS_SELECTOR,"#article_post_submit").click()
        ForumDriver.getScreenshot()
        time.sleep(2)

        # #不输入标题，输入内容
        # self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").clear()
        # self.driver.find_element(By.CSS_SELECTOR, "#edit-article > div.CodeMirror.cm-s-default.CodeMirror-wrap.CodeMirror-empty > div.CodeMirror-scroll").send_keys("测试")
        # time.sleep(5)
        # self.driver.execute("window.scrollTo(0, document.body.scrollHeight);")
        # time.sleep(0.5)
        # self.driver.find_element(By.CSS_SELECTOR, "#article_post_submit").click()
        # ForumDriver.getScreenshot()
        # time.sleep(2)

        #不输入标题，不输入内容
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_title").clear()
        self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
        time.sleep(0.5)
        self.driver.find_element(By.CSS_SELECTOR, "#article_post_submit").click()
        ForumDriver.getScreenshot()

Edit=ForumEdit()
